package com.example.util;



import com.example.pojo.RuleExcelDev;
import com.example.pojo.RuleExcelUser;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFBorderFormatting;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.apache.poi.xssf.usermodel.*;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ReadExcelRuleEngine {
    //读取用户输入的Excel



    //写入标准的Excel
    public String writeExcel(String path , String IsMatch , String ruleTableName ,String standard, List<RuleExcelUser> ruleExcelUserList,String pointName,String season){

        if(StringUtils.isBlank(standard)){
            standard = "NULL";
        }
        File file = new File(path);
        //FileInputStream in = null;
        OutputStream out = null;

        String  section="[]";
        try {
            if (file.exists()){
                //清空原有数据
                file.delete();
            }
            if (!file.getParentFile().exists()){
                file.getParentFile().mkdirs();
            }
            if (!file.exists()){
                file.createNewFile();
            }
            //in = new FileInputStream(file);
            XSSFWorkbook wb = new XSSFWorkbook();
            XSSFSheet sheet = wb.createSheet();

            XSSFRow row1 = sheet.createRow(0);
            row1.createCell(0).setCellValue("包");
            row1.createCell(1).setCellValue("RuleSet");
            row1.createCell(2).setCellValue("rules");

            XSSFRow row2 = sheet.createRow(sheet.getLastRowNum() + 1);
            row2.createCell(1).setCellValue("Import");
            row2.createCell(2).setCellValue("com.yunsitu.entity.drools.*, com.example.pojo.*");

            XSSFRow row3 = sheet.createRow(sheet.getLastRowNum() + 1);
            row3.createCell(1).setCellValue("RuleTable yunsitu_alarm_" + ruleTableName + standard + season);

            XSSFRow row4 = sheet.createRow(sheet.getLastRowNum() + 1);
            row4.createCell(1).setCellValue("CONDITION");
            row4.createCell(2).setCellValue("CONDITION");
            row4.createCell(3).setCellValue("CONDITION");
            row4.createCell(4).setCellValue("CONDITION");
            row4.createCell(5).setCellValue("CONDITION");
            row4.createCell(6).setCellValue("CONDITION");
            row4.createCell(7).setCellValue("CONDITION");

            row4.createCell(8).setCellValue("CONDITION");
            row4.createCell(9).setCellValue("ACTION");
            row4.createCell(10).setCellValue("ACTION");
            row4.createCell(11).setCellValue("ACTION");
            row4.createCell(12).setCellValue("ACTION");
            row4.createCell(13).setCellValue("ACTION");
            row4.createCell(14).setCellValue("ACTION");

            XSSFRow row5 = sheet.createRow(sheet.getLastRowNum() + 1);
            row5.createCell(1).setCellValue("$dl:DroolsTest()");
            row5.createCell(2).setCellValue("$dl1:DroolsTest()");
            row5.createCell(3).setCellValue("$dl2:DroolsTest()");
            row5.createCell(4).setCellValue("$dl3:DroolsTest()");
            row5.createCell(5).setCellValue("$dl4:DroolsTest()");
            row5.createCell(6).setCellValue("$dl5:DroolsTest()");
            row5.createCell(7).setCellValue("$dl6:DroolsTest()");
            row5.createCell(8).setCellValue("$dl7:DroolsTest()");
//            CellRangeAddress cra = new CellRangeAddress(row5.getRowNum(), row5.getRowNum(), 1, 7);
//            sheet.addMergedRegion(cra);
//            //RegionUtil.setBorderTop(HSSFBorderFormatting.BORDER_THICK, cra, sheet, wb);
//            //合并的单元格样式
//            XSSFCellStyle cellStyle = wb.createCellStyle();
//            //垂直居中
//            //cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
//            cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
//            //水平居中
//            //cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER);
//            cellStyle.setAlignment(HorizontalAlignment.CENTER);

            XSSFRow row6 = sheet.createRow(sheet.getLastRowNum() + 1);
            row6.createCell(0).setCellValue("判断条件");
            if (IsMatch.equals("类型")){
                row6.createCell(1).setCellValue("pointName matches \"$1\"");
            } else {
                row6.createCell(1).setCellValue("pointName == \"$1\"");
            }
            row6.createCell(2).setCellValue("key==\"$1\"");
            row6.createCell(3).setCellValue(" value<$1");
            row6.createCell(4).setCellValue(" value>$1");
            row6.createCell(5).setCellValue(" value<=$1");
            row6.createCell(6).setCellValue(" value>=$1");
            row6.createCell(7).setCellValue(" value==$1");
            row6.createCell(8).setCellValue("variable==\"$1\"");
            row6.createCell(9).setCellValue(" $dl.setSave(true);$dl.setInformation(\"$1\") ;System.out.println(\"$1\");");
            row6.createCell(10).setCellValue(" $dl.setMessagelevel(\"$1\");");
            row6.createCell(11).setCellValue(" System.out.println(\"$1\");");
            row6.createCell(12).setCellValue(" $dl.setMessageType(\"$1\");");
            row6.createCell(13).setCellValue("  System.out.println(\"$1\");");
            row6.createCell(14).setCellValue(" $dl.setPosition(\"$1\");");



            XSSFRow row7 = sheet.createRow(sheet.getLastRowNum() + 1);
            row7.createCell(0).setCellValue("注释");

            for (int i = 0; i < ruleExcelUserList.size(); i++){
                RuleExcelUser ruleExcelUser = ruleExcelUserList.get(i);
                int lastRowNum = sheet.getLastRowNum();

                XSSFRow row = sheet.createRow((sheet.getLastRowNum() + 1));
                row.createCell(0).setCellValue(ruleExcelUser.norm);//规则，直写
                //保养规则 如果有保养部位 则将保养部位加入判读

                if (IsMatch.equals("类型")){

                    row.createCell(1).setCellValue(pointName+".*");//设备名称，直写
                } else {
                    row.createCell(1).setCellValue(pointName);
                }
                row.createCell(2).setCellValue(ruleExcelUser.variableName);//变量名称，直写
                //"\"" + ruleExcelUser.variableName + "=\"+$dl.getValue()+\"" + ruleExcelUser.alarmDescribe + "\""
                row.createCell(8).setCellValue(ruleExcelUser.variable);//基准变量
                row.createCell(9).setCellValue(ruleExcelUser.alarmDescribe);//报警描述，拼接
                row.createCell(10).setCellValue(ruleExcelUser.messagelevel);//信息等级
                row.createCell(11).setCellValue(ruleExcelUser.season);//季节
                row.createCell(12).setCellValue(ruleExcelUser.messageType);//报警类型
                row.createCell(13).setCellValue(ruleExcelUser.unit);//单位
                row.createCell(14).setCellValue(ruleExcelUser.position);//保养部位

                if (ruleExcelUser.mark.equals(section)){//区间内
                    row.createCell(3).setCellValue(ruleExcelUser.num2);
                    row.createCell(4).setCellValue(ruleExcelUser.num1);
                } else if (ruleExcelUser.mark.equals("<>")){//区间外
                    row.createCell(3).setCellValue(ruleExcelUser.num1);
                    row.createCell(4).setCellValue(ruleExcelUser.num2);
                } else {//单条件
                    if (ruleExcelUser.mark.equals("<")){
                        row.createCell(3).setCellValue(ruleExcelUser.num1);
                    } else if (ruleExcelUser.mark.equals(">")){
                        row.createCell(4).setCellValue(ruleExcelUser.num1);
                    } else if (ruleExcelUser.mark.equals("≤")){
                        row.createCell(5).setCellValue(ruleExcelUser.num1);
                    } else if (ruleExcelUser.mark.equals("≥")){
                        row.createCell(6).setCellValue(ruleExcelUser.num1);
                    } else if (ruleExcelUser.mark.equals("=") || ruleExcelUser.mark.equals("==")){
                        row.createCell(7).setCellValue(ruleExcelUser.num1);
                    }
                }
            }
            out = new FileOutputStream(path);
            out.flush();
            wb.write(out);
            wb.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException exception) {
            exception.printStackTrace();
        }

        return "写入Excel完毕";
    }

    //逆转义：读取标准Excel
    public List<RuleExcelDev> readNormExcel(File file){
        List<RuleExcelDev> ruleExcelDevList = new ArrayList<>();
        try {
            //InputStream is = new FileInputStream(file.getAbsolutePath());
            //Workbook wb = WorkbookFactory.create(new File("E:/2.1_Work/1_Codes/5_RuleEngine/drools.xls"));
            Workbook wb = WorkbookFactory.create(file);

            // Excel的页签数量
            int sheet_size = wb.getNumberOfSheets();
            for (int index = 0; index < sheet_size; index++) {
                Sheet sheet = wb.getSheetAt(index);
                for (int i = 7; i < sheet.getLastRowNum() + 1; i++) {
                    try {
                        RuleExcelDev ruleExcelDev = new RuleExcelDev();
                        if (null != sheet.getRow(i).getCell(0)){
                            ruleExcelDev.norm = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(0)));//规范名称与编号
                            if (ruleExcelDev.norm.equals("")){
                                ruleExcelDev.norm = getMergedRegionValue(sheet,i,0);
                            }
                        }
                        if (null != sheet.getRow(i).getCell(1)){
                            ruleExcelDev.deviceName = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(1)));//设备名称
                            if (ruleExcelDev.deviceName.equals("")){
                                ruleExcelDev.deviceName = getMergedRegionValue(sheet,i,1);
                            }
                        }
                        if (null != sheet.getRow(i).getCell(2)){
                            ruleExcelDev.variableName = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(2)));//变量名称
                            if (ruleExcelDev.variableName.equals("")){
                                ruleExcelDev.variableName = getMergedRegionValue(sheet,i,2);
                            }
                        }
                        if (null != sheet.getRow(i).getCell(3)){
                            ruleExcelDev.valueLess = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(3)));//小于条件
                        }
                        if (null != sheet.getRow(i).getCell(4)){
                            ruleExcelDev.valueGreater = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(4)));//大于条件
                        }
                        if (null != sheet.getRow(i).getCell(5)){
                            ruleExcelDev.valueLessEqual = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(5)));//小于等于条件
                        }
                        if (null != sheet.getRow(i).getCell(6)){
                            ruleExcelDev.valueGreaterEqual = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(6)));//大于等于条件
                        }
                        if (null != sheet.getRow(i).getCell(7)){
                            ruleExcelDev.valueEqual = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(7)));//等于条件
                        }

                        ruleExcelDev.variable= String.valueOf(getValueFromCell(sheet.getRow(i).getCell(8)));//基准变量
                        ruleExcelDev.alarmAction = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(9)));//报警信息【全部】
                        ruleExcelDev.messagelevel = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(10)));//报警等级
                        ruleExcelDev.season = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(11)));//季节
                        ruleExcelDev.messageType = String.valueOf(getValueFromCell(sheet.getRow(i).getCell(12)));
//                        getValueFromCell(sheet.getRow(i).getCell(12));//报警分类
                        ruleExcelDev.unit= String.valueOf(getValueFromCell(sheet.getRow(i).getCell(13)));//单位
                        ruleExcelDev.position= String.valueOf(getValueFromCell(sheet.getRow(i).getCell(14)));//保养部位
                        ruleExcelDevList.add(ruleExcelDev);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                wb.close();
                return ruleExcelDevList;
            }

        } catch (IOException | InvalidFormatException e) {
            e.printStackTrace();
        }
        return null;
    }
    //逆转义
    public String writeUserExcel(String path , List<RuleExcelDev> ruleExcelDevList){
        try {
            File file = new File(path);
            if (file.exists()){
                //清空原有数据
                file.delete();
            }
            if (!file.getParentFile().exists()){
                file.mkdirs();
            }
            if (!file.exists()){
                file.createNewFile();
            }
            //FileInputStream inputStream = new FileInputStream(file);
            XSSFWorkbook workbook = new XSSFWorkbook();
            XSSFSheet sheet = workbook.createSheet();
            // org.apache.poi.ss.usermodel.Workbook sheets = WorkbookFactory.create(inputStream);
            // org.apache.poi.ss.usermodel.Sheet sheet = sheets.createSheet();
            XSSFRow row = sheet.createRow(0);
            row.createCell(0);row.createCell(1);row.createCell(2);
            row.createCell(3);row.createCell(4);row.createCell(5);
            row.createCell(6);row.createCell(7);row.createCell(8);
            row.getCell(0).setCellValue("规范名称与编号");
            row.getCell(1).setCellValue("设备名称");
            row.getCell(2).setCellValue("变量名称");
            row.getCell(3).setCellValue("条件1");
            row.getCell(4).setCellValue("and/or");
            row.getCell(5).setCellValue("条件2");
            row.getCell(6).setCellValue("and/or");
            row.getCell(7).setCellValue("条件3");
            row.getCell(8).setCellValue("报警描述");
            row.getCell(9).setCellValue("报警等级");
            row.getCell(10).setCellValue("季节");
            row.getCell(11).setCellValue("报警分类");
            for (int index = 0; index < ruleExcelDevList.size(); index++) {
                RuleExcelDev ruleExcelDev = ruleExcelDevList.get(index);
            //for (RuleExcelDev ruleExcelDev : ruleExcelDevList) {
                XSSFRow row1 = sheet.createRow(1 + index);
                row1.createCell(0);row1.createCell(1);row1.createCell(2);
                row1.createCell(3);row1.createCell(4);row1.createCell(5);
                row1.createCell(6);row1.createCell(7);row1.createCell(8);
                row1.createCell(9);
                row1.getCell(0).setCellValue(ruleExcelDev.norm);//规则
                row1.getCell(1).setCellValue(ruleExcelDev.deviceName);//设备名称
                row1.getCell(2).setCellValue(ruleExcelDev.variableName);//参数名称
                if (null != ruleExcelDev.valueLess){
                    row1.getCell(3).setCellValue("<" + ruleExcelDev.valueLess);//小于条件
                } else if (null != ruleExcelDev.valueLessEqual){
                    row1.getCell(3).setCellValue("≤" + ruleExcelDev.valueLessEqual);//小于等于条件
                }
                if (null != ruleExcelDev.valueGreater){
                    if (null != row1.getCell(3).getStringCellValue()){
                        row1.getCell(4).setCellValue("and");//and/or
                        row1.getCell(5).setCellValue(">" + ruleExcelDev.valueGreater);//大于条件
                    } else {
                        row1.getCell(3).setCellValue(">" + ruleExcelDev.valueGreater);//大于条件
                    }
                } else if (null != ruleExcelDev.valueGreaterEqual){
                    if (null != row1.getCell(3).getStringCellValue()){
                        row1.getCell(4).setCellValue("and");//and/or
                        row1.getCell(5).setCellValue("≥" + ruleExcelDev.valueGreaterEqual);//大于等于条件
                    } else {
                        row1.getCell(3).setCellValue("≥" + ruleExcelDev.valueGreaterEqual);//大于等于条件
                    }
                }
                if (null != ruleExcelDev.valueEqual){
                    if (null != row1.getCell(3).getStringCellValue()
                    && null != row1.getCell(5).getStringCellValue()){
                        row1.getCell(6).setCellValue("and");//and/or
                        row1.getCell(7).setCellValue("=" + ruleExcelDev.valueEqual);//等于条件
                    } else if (null != row1.getCell(3).getStringCellValue()
                            && null != row1.getCell(5).getStringCellValue()){
                        row1.getCell(4).setCellValue("and");//and/or
                        row1.getCell(5).setCellValue("=" + ruleExcelDev.valueEqual);//等于条件
                    } else {
                        row1.getCell(3).setCellValue("=" + ruleExcelDev.valueEqual);//等于条件
                    }
                }
//                String[] split = ruleExcelDev.alarmAction.split("\"");
//                String describe = split[split.length-1];
//                row1.getCell(8).setCellValue(describe);//报警描述
                row1.getCell(8).setCellValue(ruleExcelDev.alarmAction);//报警描述
                row1.getCell(9).setCellValue(ruleExcelDev.messagelevel);//警报等级
                row1.getCell(10).setCellValue(ruleExcelDev.season);//季节
                row1.getCell(11).setCellValue(ruleExcelDev.messageType);//报警分类
            }

            FileOutputStream outputStream = new FileOutputStream(file);
            workbook.write(outputStream);
            outputStream.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException exception) {
            exception.printStackTrace();
        }


        return " ";
    }

    //根据表格类型自动获取表格内容
    private static Object getValueFromCell(Cell cell) {
        Object cellValue = null;
        if(cell == null) {
            return "";
        }

        else if(cell.getCellType() == Cell.CELL_TYPE_STRING) {
            cellValue = cell.getStringCellValue();
        }

        else if(cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
            if(HSSFDateUtil.isCellDateFormatted(cell)) {
                double d = cell.getNumericCellValue();
                cellValue = HSSFDateUtil.getJavaDate(d);
            }else {
                double d = cell.getNumericCellValue();
                double _1 = Math.floor(d);
                if (_1<d) { //有小數部分
                    cellValue = d;
                }else { //無小數部分
                    long _2 = Math.round(_1);
                    if (_2>Integer.MAX_VALUE || _2<Integer.MIN_VALUE) {
                        cellValue = _2;
                    }else {
                        cellValue = (int)_2;
                    }
                }
            }
        }

        else if(cell.getCellType() == Cell.CELL_TYPE_BLANK) {
            cellValue = "";
        }

        else if(cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
            cellValue = cell.getBooleanCellValue();
        }

        else if(cell.getCellType() == Cell.CELL_TYPE_ERROR) {
            cellValue = "";
        }

        else if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
            cellValue = cell.getCellFormula();
        }

        return cellValue;
    }
    //获取合并单元格内容
    public static String getMergedRegionValue(Sheet sheet ,int row , int column){
        int sheetMergeCount = sheet.getNumMergedRegions();
        for(int i = 0 ; i < sheetMergeCount ; i++){
            CellRangeAddress ca = sheet.getMergedRegion(i);
            int firstColumn = ca.getFirstColumn();
            int lastColumn = ca.getLastColumn();
            int firstRow = ca.getFirstRow();
            int lastRow = ca.getLastRow();
            if(row >= firstRow && row <= lastRow){
                if(column >= firstColumn && column <= lastColumn){
                    Row fRow = sheet.getRow(firstRow);
                    Cell fCell = fRow.getCell(firstColumn);
                    return String.valueOf(getValueFromCell(fCell));
                }
            }
        }
        return "";
    }

    //Out转In
    public RuleExcelUser tranRuleExcelOut(RuleExcelDev ruleExcelDev){
        RuleExcelUser ruleExcelUser = new RuleExcelUser();
        ruleExcelUser.norm = ruleExcelDev.norm;
        ruleExcelUser.deviceName = ruleExcelDev.deviceName;
        ruleExcelUser.variableName = ruleExcelDev.variableName;

        ruleExcelUser.alarmDescribe = ruleExcelDev.alarmAction;
        ruleExcelUser.messagelevel = ruleExcelDev.messagelevel;
        ruleExcelUser.season = ruleExcelDev.season;
        ruleExcelUser.messageType = ruleExcelDev.messageType;
        ruleExcelUser.unit = ruleExcelDev.unit;
        ruleExcelUser.position = ruleExcelDev.position;
        ruleExcelUser.variable = ruleExcelDev.variable;
        String  section="[]";
        //先多条件
        if (StringUtils.isNotBlank(ruleExcelDev.valueLess) && StringUtils.isNotBlank(ruleExcelDev.valueGreater)){//大于 小于
            if (Double.valueOf(ruleExcelDev.valueLess) < Double.valueOf(ruleExcelDev.valueGreater)){//区间外
                ruleExcelUser.mark = "<>";
                ruleExcelUser.num1 = Double.valueOf(ruleExcelDev.valueLess);
                ruleExcelUser.num2 = Double.valueOf(ruleExcelDev.valueGreater);
            } else {//区间内
                ruleExcelUser.mark = section;
                ruleExcelUser.num1 = Double.valueOf(ruleExcelDev.valueGreater);
                ruleExcelUser.num2 = Double.valueOf(ruleExcelDev.valueLess);
            }
        } else if (StringUtils.isNotBlank(ruleExcelDev.valueLessEqual) && StringUtils.isNotBlank(ruleExcelDev.valueGreaterEqual)){//大于等于 小于等于
            if (Double.valueOf(ruleExcelDev.valueLessEqual) < Double.valueOf(ruleExcelDev.valueGreaterEqual)){//区间外
                ruleExcelUser.mark = "<>";
                ruleExcelUser.num1 = Double.valueOf(ruleExcelDev.valueLessEqual);
                ruleExcelUser.num2 = Double.valueOf(ruleExcelDev.valueGreaterEqual);
            } else {//区间内
                ruleExcelUser.mark = section;
                ruleExcelUser.num1 = Double.valueOf(ruleExcelDev.valueGreaterEqual);
                ruleExcelUser.num2 = Double.valueOf(ruleExcelDev.valueLessEqual);
            }
        }
        //再单条件
        else if (StringUtils.isNotBlank( ruleExcelDev.valueLess)){//小于
            ruleExcelUser.mark = "<";
            ruleExcelUser.num1 = Double.valueOf(ruleExcelDev.valueLess);
        } else if (StringUtils.isNotBlank( ruleExcelDev.valueGreater)){//大于
            ruleExcelUser.mark = ">";
            ruleExcelUser.num1 = Double.valueOf(ruleExcelDev.valueGreater);
        } else if (StringUtils.isNotBlank( ruleExcelDev.valueLessEqual)){//小于等于
            ruleExcelUser.mark = "≤";
            ruleExcelUser.num1 = Double.valueOf(ruleExcelDev.valueLessEqual);
        } else if (StringUtils.isNotBlank(  ruleExcelDev.valueGreaterEqual)){//大于等于
            ruleExcelUser.mark = "≥";
            ruleExcelUser.num1 = Double.valueOf(ruleExcelDev.valueGreaterEqual);
        } else if (StringUtils.isNotBlank(  ruleExcelDev.valueEqual)){//等于
            ruleExcelUser.mark = "=";
            ruleExcelUser.num1 = Double.valueOf(ruleExcelDev.valueEqual);
        }
        return ruleExcelUser;
    }
    //In转Out
    public RuleExcelDev tranRuleExcelIn(RuleExcelUser ruleExcelUser){
        RuleExcelDev ruleExcelDev = new RuleExcelDev();
        ruleExcelDev.norm = ruleExcelUser.norm;
        ruleExcelDev.deviceName = ruleExcelUser.deviceName;
        ruleExcelDev.variableName = ruleExcelUser.variableName;
        ruleExcelDev.alarmAction = "\"" + ruleExcelUser.variableName + "=\"+$dl.getValue()+\"" + ruleExcelUser.alarmDescribe + "\"";
        String  section="[]";
        if (ruleExcelUser.mark.equals(section)){//区间内
            ruleExcelDev.valueLess = String.valueOf(ruleExcelUser.num2);
            ruleExcelDev.valueGreater = String.valueOf(ruleExcelUser.num1);
        } else if (ruleExcelUser.mark.equals("<>")){//区间外
            ruleExcelDev.valueLess = String.valueOf(ruleExcelUser.num1);
            ruleExcelDev.valueGreater = String.valueOf(ruleExcelUser.num2);
        } else if (ruleExcelUser.mark.equals("<")){//小于
            ruleExcelDev.valueLess = String.valueOf(ruleExcelUser.num1);
        } else if (ruleExcelUser.mark.equals(">")){//大于
            ruleExcelDev.valueGreater = String.valueOf(ruleExcelUser.num1);
        } else if (ruleExcelUser.mark.equals("≤")){//小于等于
            ruleExcelDev.valueLessEqual = String.valueOf(ruleExcelUser.num1);
        } else if (ruleExcelUser.mark.equals("≥")){//大于等于
            ruleExcelDev.valueGreaterEqual = String.valueOf(ruleExcelUser.num1);
        } else if (ruleExcelUser.mark.equals("=")){//等于
            ruleExcelDev.valueEqual = String.valueOf(ruleExcelUser.num1);
        }
        ruleExcelDev.messagelevel = ruleExcelUser.messagelevel;
        ruleExcelDev.season = ruleExcelUser.season;
        ruleExcelDev.messageType = ruleExcelUser.messageType;
        return ruleExcelDev;
    }

    //前端传递数据
    public Map<String,String> getHeaders(){
        Map<String,String> headers = new HashMap<>();

        headers.put("规范名称与编号","norm");
        headers.put("设备名称","deviceName");
        headers.put("变量名称","variableName");
        headers.put("符号","mark");
        headers.put("数值1","num1");
        headers.put("数值2","num2");
//        headers.put("条件1","condition1");
//        headers.put("and/or1","andOrGate1");
//        headers.put("条件2","condition2");
//        headers.put("and/or2","andOrGate2");
//        headers.put("条件3","condition3");
        headers.put("报警描述","alarmDescribe");
        headers.put("报警等级","messageLevel");
        headers.put("季节","season");

        return headers;
    }
}
